<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!DOCTYPE html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]-->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"><![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9"><![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
    <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>Token Generation</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">

        <link rel="shortcut icon" href="images/favicon.ico">
        <link href="styles/bootstrap.min.css" media="all" rel="stylesheet" type="text/css" id="bootstrap-css">
        <link href="styles/knox.css" media="all" rel="stylesheet" type="text/css">

        <script src="libs/bower/jquery/js/jquery-3.5.1.min.js" ></script>
        <script type="text/javascript" src="js/tokengen.js"></script>
        <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    
        <script type="text/javascript">
           $(function() {
                var updateBoxPosition = function() {
                    $('#signin-container').css({
                        'margin-top' : ($(window).height() - $('#signin-container').height()) / 2
                    });
                };
                $(window).resize(updateBoxPosition);
                setTimeout(updateBoxPosition, 50);
            });
        </script>

    </head>
    <body class="login" style="" onload="setTokenStateServiceStatus()">
        <div style="margin-left: 1.75%; margin-right: 1.75%; margin-top: 4.5px">
            <form action="" method="get" accept-charset="utf-8">
                <fieldset>
                    <div class="fields">
                        <h3>Token Generation</h3>
                        <label id="tokenStateServiceStatusInfo" style="color: green;"></label>
                        <label id="tokenStateServiceStatusError" style="color: red;"></label>
                        <label id="tokenStateServiceStatusWarning" style="color: yellow;"></label>
                        <label><i class="icon-info"></i> Token Generation enables integration and API invocations by using the
                         token as an authorization bearer token. Copy the JWT token from the resulting text area and protect it
                         securely from others as this token represents your identity and is active until expired.</label>

                        <label><i class="icon-comment"></i> Comment:</label>
                        <input type="text" name="comment" id="comment" tabindex="1" onkeypress=keypressed(event) autofocus size="255" maxlength="255">
                        <label style="display: none; color: red;" id="invalidCommentText"><i class="icon-warning"></i>Invalid comment!</label>

                        <label><i class="icon-info"></i> Configured maximum lifetime: </label>
                        <label id="maximumLifetimeText"></label>
                        <input type="number" id="maximumLifetimeSeconds" name="maximumLifetimeSeconds" style="display: none;">
                        <div id="lifespanFields" style="display: none;">
                            <input id="lifespanInputEnabled" name="lifespanInputEnabled" type="text" style="display: none" value="false" />
                            <label><i class="icon-time"></i> Lifetime (days, hours, mins):</label>
                            <table>
                                <tr>
                                    <td><input type="number" id="lt_days" name="lt_days" step="1" min="0" max="3650" value="0" size="3"></td> <!-- 10 years limit -->
                                    <td><input type="number" id="lt_hours" name="lt_hours" step="1" min="0" max="23" value="1" size="3"></td>
                                    <td><input type="number" id="lt_mins" name="lt_mins" step="1" min="0" max="59" value="0" size="3"></td>
                                </tr>
                            </table>
                            <label style="display: none; color: red;" id="invalidLifetimeText"><i class="icon-warning"></i>Invalid lifetime!</label>
                        </div>
                    </div>
                    <span id="errorBox" class="help-inline" style="color:red;display:none;"><span class="errorMsg"></span>
                        <i class="icon-warning-sign" style="color:#ae2817;"></i>
                    </span>
                    <div style="align-content: center; width: 25%;">
                        <button type="button" class="btn btn-primary btn-block" id="genToken" tabindex="2" onkeypress="keypressed(event)" onclick="gen();">
                            Generate Token
                        </button>
                    </div>
                </fieldset>
            </form>
        </div>
        <div style="margin-left: 1.75%; margin-right: 1.75%; margin-top: 10px">
            <span id="resultBox" style="color:black; display:none; margin-left: 1.75%; margin-right: 1.75%;">

               <label id="jwtAccessTokenLabel" onclick="copyTextToClipboard('accessToken');"><i class="icon-copy"></i> JWT Token:</label>
               <div class="tokenResultDisplay">
                   <span id="accessToken" name="accessToken" style="word-wrap: break-word"></span>
               </div>

               <label id="jwtPasscodeTokenLabel" onclick="copyTextToClipboard('accessPasscode');"><i class="icon-copy"></i> Passcode Token:</label>
               <div class="tokenResultDisplay">
                   <span id="accessPasscode" name="accessPasscode"></span>
               </div>

               <label><i class="icon-info"></i> Expiration:</label>
               <div class="tokenResultDisplay">
                   <span id="expiry" name="expiry"></span>
               </div>

               <label><i class="icon-info"></i> User:</label>
               <div class="tokenResultDisplay">
                   <span id="user" name="user"></span>
               </div>

               <label id="targetBaseUrlLabel" onclick="copyTextToClipboard('target_url');"><i class="icon-copy"></i> Target Base URL:</label>
               <div class="tokenResultDisplay">
                   <span id="target_url" name="target_url"></span>
               </div>

               <label><i class="icon-link"></i> Homepage:</label>
               <div class="tokenResultDisplay">
                   <span id="homepage_url" name="homepage_url"></span>
               </div>
            </span>
        </div>
    </body>
</html>
